/**
 * @implements TransitionI
 */
export default class Line {

  _value;
  start;
  target;
  length;
  current;
  changing = false;

  spacing = 0;

  /**
   * @param { number } value
   * @param { number } length
   */
  constructor(value, length) {
    this._value = value;
    this.start = value;
    this.target = value;
    this.length = length;
    this.current = length;
  }

  get value() {
    return this._value
  }
  set value(val) {
    this.start = this._value;
    this.target = val;
    this.current = 1;
    this.spacing = (this.target - this.start) / (this.length - 1);
    this.changing = true;
  }

  trigger() {
    if (this.changing) {
      this.current++;
      if(this.current === this.length) {
        this._value = this.target;
        this.changing = false;
      } else {
        this._value += this.spacing;
      }
    }
  }
}
